<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>产品销售数量分析</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var beginDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '日期从',
          name: 'begin_date',
          id: 'volume_begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",          
          anchor: '95%',
          vtype: 'daterange',
          endDateField: 'volume_end_date'
        });

        var endDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '至    ',labelWidth:30,
          name: 'end_date',
          id: 'volume_end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          
          anchor: '95%',
          vtype: 'daterange',
          startDateField: 'volume_begin_date'
        });

        var timeSlot = Ext.create('Ext.form.RadioGroup', {
          //width : 220,
          name:'time_slot',
          fieldLabel: '时间分段',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          columns : 4,
          anchor: '100%',
          vertical :false,
          items:[
            {boxLabel:'无',inputValue:'none',name:'time_slot',checked:true},
            {boxLabel:'日',inputValue:'day',name:'time_slot'},
            {boxLabel:'月',inputValue:'month',name:'time_slot'},
            {boxLabel:'年',inputValue:'year',name:'time_slot'}
          ]
        });
        
        var submitButton = Ext.create('Ext.Button', {
          text: '执行统计',
          iconCls: 'finding',
          handler: function(){
            if (queryFormPanel.form.isValid()) {
              statsResultDS.removeAll();
              statsResultDS.getProxy().extraParams.begin_date = beginDate.getRawValue();
              statsResultDS.getProxy().extraParams.end_date = endDate.getRawValue();
              statsResultDS.getProxy().extraParams.time_slot = timeSlot.getValue();
              statsResultDS.load();
            }
          }
        });

        var clearButton = Ext.create('Ext.Button', {
          text: '清空',
          width:50,
          handler: function(){
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 65,
            labelAlign: 'right'
          },
          width: screenWidth-165,
          frame : true,
          border:false,
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1100},
              title: '统计条件',
              border: true,
              items: [{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .16,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [beginDate]
                    }, {
                      columnWidth: .13,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [endDate]
                    }, {
                      columnWidth: .28,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [timeSlot]
                    }, {
                      columnWidth: .12,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [submitButton]
                    }, {
                      columnWidth: .12,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [clearButton]
                    }]
                }]
            }]
        });
        //显示销售订单操作时的窗口介面。
        //----------------------------------销售订单Grid-------------------------
        //销售订单Grid Store
        Ext.define('SaleVolumeReportModel', {
          extend : 'Ext.data.Model',
          fields : [{name: 'id'},
            {
              name: 'product_name'
            },{
              name: 'product_number'
            },{
              name: 'unit_price',
              type: 'float'
            },{
              name: 'quantity',
              type: 'int'
            },{
              name: 'time_slot',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value;
                }
              }
            }
          ]
        });

        var statsResultDS =  Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'SaleVolumeReportModel',
          proxy : {
            type : 'ajax',
            url : '/sale_order/getProductSalesVolumeForReport',
            reader : {
              type : 'json',
              root : 'root',// JSON数组对象名
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          }
        });

        //生成要订单的产品的Grid
        var statsResultGrid = Ext.create('Ext.grid.Panel', {
          title:'统计结果列表',
          store: statsResultDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: '销售数量',
              dataIndex: 'quantity',
              align:'right',
              width: 100
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 200
            },{
              header: '产品编号',
              dataIndex: 'product_number',
              width: 170
            },{
              header: '单件均价',
              dataIndex: 'unit_price',
              align:'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 100
            },{
              header: '时间段',
              dataIndex: 'time_slot',
              width: 95
            }],
          loadMask: true,
          width: screenWidth-165,
          height: screenHeight-340,
          frame: true         
        });    

        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-165,
          height: screenHeight-240,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[queryFormPanel,statsResultGrid]
        });
        workbenchPanel.render("sales_volume_report_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="sales_volume_report_workbench_panel"></div>
  </body>
</html>